package cn.ante.ymcc.mqconsumer;

import cn.ante.ymcc.domain.MessageSms;
import cn.ante.ymcc.service.IMessageSmsService;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(consumerGroup = "service-course-smsconsumer",topic="topic-course",
selectorExpression = "tags-smscourse")
public class CourseConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private IMessageSmsService messageSmsService;

    @Override
    public void onMessage(MessageExt message) {
            String s = new String(message.getBody(), StandardCharsets.UTF_8);
            MessageSms messageSms = JSONObject.parseObject(s, MessageSms.class);
            messageSmsService.insert(messageSms);
    }
}
